#include <a_samp>
#include <YSI\y_ini>
#include <foreach>
#include <zcmd>

//msg
new stringo[256];
#define SendClientMessage(%1,%2,%3,%4);   format(stringo, 256, %3, %4); SendClientMessage(%1, %2, stringo);
#define SendClientMessageToAll(%1,%2,%3);   format(stringo, 256, %2, %3); SendClientMessageToAll(%1, stringo);

// def
#define ADMIN_REQ               "You must be admin"         // default message for admin cmds

//colors
#define yellow	 				0xFFFF00AA
#define green 					0x33FF33AA
#define red 					0xFF0000AA
#define white 					0xFFFFFFAA
#define pink 					0xCCFF00FF
#define blue 					0x00FFFFAA
#define grey 					0xC0C0C0AA
#define COLOR_SYSTEM 			0x94CC1DAA
#define COLOR_JOIN 				0x61B000AA
#define COLOR_LEFT 				0xD60019AA
#define COLOR_GREY 				0xAFAFAFAA //grigio
#define COLOR_GREEN 			0x33AA33AA //verde
#define COLOR_RED				red		   //rosso
#define COLOR_YELLOW 			0xFFFF00AA //giallo
#define COLOR_PINK 				0xFF66FFAA //rosa
#define COLOR_BLUE 				0x0000BBAA //blu
#define COLOR_ORANGE 			0xFF9900AA //arancione
#define COLOR_PURPLE 			0x990099AA //viola
#define COLOR_BROWN 			0x663300AA //marrone
#define COLOR_LIGHTBLUE 		0x33CCFFAA //azzurro
#define COLOR_DARKRED 			0x660000AA //rosso scuro
#define COLOR_DARKBLUE 			0x000066AA //blu scuro
#define COLOR_WHITE 			0xFFFFFFAA

// game setting
#define GAME_VERSION    "1.0"
#define SCRIPT_LOCATION "LiteAD"
#define TeamFile        SCRIPT_LOCATION"/teams.ini"
#define ConfigFile      SCRIPT_LOCATION"/config.ini"

//define
#define MAX_BASES       44
#define MAX_ARENE       29

// vehicles
new aVehicleNames[212][] = {	// Vehicle Names - Betamaster
	{"Landstalker"},
	{"Bravura"},
	{"Buffalo"},
	{"Linerunner"},
	{"Perrenial"},
	{"Sentinel"},
	{"Dumper"},
	{"Firetruck"},
	{"Trashmaster"},
	{"Stretch"},
	{"Manana"},
	{"Infernus"},
	{"Voodoo"},
	{"Pony"},
	{"Mule"},
	{"Cheetah"},
	{"Ambulance"},
	{"Leviathan"},
	{"Moonbeam"},
	{"Esperanto"},
	{"Taxi"},
	{"Washington"},
	{"Bobcat"},
	{"Mr Whoopee"},
	{"BF Injection"},
	{"Hunter"},
	{"Premier"},
	{"Enforcer"},
	{"Securicar"},
	{"Banshee"},
	{"Predator"},
	{"Bus"},
	{"Rhino"},
	{"Barracks"},
	{"Hotknife"},
	{"Trailer 1"}, //artict1
	{"Previon"},
	{"Coach"},
	{"Cabbie"},
	{"Stallion"},
	{"Rumpo"},
	{"RC Bandit"},
	{"Romero"},
	{"Packer"},
	{"Monster"},
	{"Admiral"},
	{"Squalo"},
	{"Seasparrow"},
	{"Pizzaboy"},
	{"Tram"},
	{"Trailer 2"}, //artict2
	{"Turismo"},
	{"Speeder"},
	{"Reefer"},
	{"Tropic"},
	{"Flatbed"},
	{"Yankee"},
	{"Caddy"},
	{"Solair"},
	{"Berkley's RC Van"},
	{"Skimmer"},
	{"PCJ-600"},
	{"Faggio"},
	{"Freeway"},
	{"RC Baron"},
	{"RC Raider"},
	{"Glendale"},
	{"Oceanic"},
	{"Sanchez"},
	{"Sparrow"},
	{"Patriot"},
	{"Quad"},
	{"Coastguard"},
	{"Dinghy"},
	{"Hermes"},
	{"Sabre"},
	{"Rustler"},
	{"ZR-350"},
	{"Walton"},
	{"Regina"},
	{"Comet"},
	{"BMX"},
	{"Burrito"},
	{"Camper"},
	{"Marquis"},
	{"Baggage"},
	{"Dozer"},
	{"Maverick"},
	{"News Chopper"},
	{"Rancher"},
	{"FBI Rancher"},
	{"Virgo"},
	{"Greenwood"},
	{"Jetmax"},
	{"Hotring"},
	{"Sandking"},
	{"Blista Compact"},
	{"Police Maverick"},
	{"Boxville"},
	{"Benson"},
	{"Mesa"},
	{"RC Goblin"},
	{"Hotring Racer A"}, //hotrina
	{"Hotring Racer B"}, //hotrinb
	{"Bloodring Banger"},
	{"Rancher"},
	{"Super GT"},
	{"Elegant"},
	{"Journey"},
	{"Bike"},
	{"Mountain Bike"},
	{"Beagle"},
	{"Cropdust"},
	{"Stunt"},
	{"Tanker"}, //petro
	{"Roadtrain"},
	{"Nebula"},
	{"Majestic"},
	{"Buccaneer"},
	{"Shamal"},
	{"Hydra"},
	{"FCR-900"},
	{"NRG-500"},
	{"HPV1000"},
	{"Cement Truck"},
	{"Tow Truck"},
	{"Fortune"},
	{"Cadrona"},
	{"FBI Truck"},
	{"Willard"},
	{"Forklift"},
	{"Tractor"},
	{"Combine"},
	{"Feltzer"},
	{"Remington"},
	{"Slamvan"},
	{"Blade"},
	{"Freight"},
	{"Streak"},
	{"Vortex"},
	{"Vincent"},
	{"Bullet"},
	{"Clover"},
	{"Sadler"},
	{"Firetruck LA"}, //firela
	{"Hustler"},
	{"Intruder"},
	{"Primo"},
	{"Cargobob"},
	{"Tampa"},
	{"Sunrise"},
	{"Merit"},
	{"Utility"},
	{"Nevada"},
	{"Yosemite"},
	{"Windsor"},
	{"Monster A"}, //monstera
	{"Monster B"}, //monsterb
	{"Uranus"},
	{"Jester"},
	{"Sultan"},
	{"Stratum"},
	{"Elegy"},
	{"Raindance"},
	{"RC Tiger"},
	{"Flash"},
	{"Tahoma"},
	{"Savanna"},
	{"Bandito"},
	{"Freight Flat"}, //freiflat
	{"Streak Carriage"}, //streakc
	{"Kart"},
	{"Mower"},
	{"Duneride"},
	{"Sweeper"},
	{"Broadway"},
	{"Tornado"},
	{"AT-400"},
	{"DFT-30"},
	{"Huntley"},
	{"Stafford"},
	{"BF-400"},
	{"Newsvan"},
	{"Tug"},
	{"Trailer 3"}, //petrotr
	{"Emperor"},
	{"Wayfarer"},
	{"Euros"},
	{"Hotdog"},
	{"Club"},
	{"Freight Carriage"}, //freibox
	{"Trailer 3"}, //artict3
	{"Andromada"},
	{"Dodo"},
	{"RC Cam"},
	{"Launch"},
	{"Police Car (LSPD)"},
	{"Police Car (SFPD)"},
	{"Police Car (LVPD)"},
	{"Police Ranger"},
	{"Picador"},
	{"S.W.A.T. Van"},
	{"Alpha"},
	{"Phoenix"},
	{"Glendale"},
	{"Sadler"},
	{"Luggage Trailer A"}, //bagboxa
	{"Luggage Trailer B"}, //bagboxb
	{"Stair Trailer"}, //tugstair
	{"Boxville"},
	{"Farm Plow"}, //farmtr1
	{"Utility Trailer"} //utiltr1
};

// worlds
#define GAME_WORLD      100
#define NORMAL_WORLD    0

//teams
#define MAX_TEAMS       4
enum {
	TEAM_NULL,
	TEAM_A,
	TEAM_B,
	TEAM_REF
}

// role
enum {
	ATTACKERS,
	DEFENDERS,
	REFEREE
}

// update td part
enum {
    TD_PART_TEAMA,
    TD_PART_TEAMB,
    TD_PART_CENTER
}

// wintype
enum {
    WINTYPE_TIMER,
	WINTYPE_ELIMINAZIONE,
	WINTYPE_CHECKPOINT,
    WINTYPE_ENDING,
    WINTYPE_ALLDEATH
}

// dialog ids
enum {
    DIALOG_HELP,
    DIALOG_SWITCH,
    DIALOG_GUNMENU_STEP1,
    DIALOG_GUNMENU_STEP2,
    DIALOG_GUNMENU_STEPCONFIRM,
    DIALOG_FINALROUND,
    DIALOG_VEHLIST
}

//td
new Text:TextDraw_RoundStats[6];
new PlayerText:TD_Gunmenu_Weapons[4];
new PlayerText:TD_Player_Damages[2];

//enum
enum eBases {
	bool:Exist,
	Float:SpawnAtt[3],
	Float:SpawnDef[3],
	Float:Checkpoint[3],
	Interior
}
new iBases[MAX_BASES][eBases];

enum eArene {
    bool:Exist,
	Float:SpawnAtt[3],
	Float:SpawnDef[3],
	Float:Center[3],
	Interior
}
new iArene[MAX_ARENE][eArene];

//config
enum eConfig {
	RoundTime,			// tempo round attuale
	ConfigTime,			// tempo del file config
	RoundSecs,          // seconds
	RoundCPTime,    	// round cp time
	ConfigCPTime,   	// config round cp
	bool:UseCp,     	// enable/disable cp
	CurrentRound,   	// current playing round
	TotalRounds,    	// config total round
	Float:Lobby[4], 	// lobby
	bool:RoundStarted 	// round started
}
new gConfig[eConfig];
new StartedBase;
new RoundPaused;

//team
enum eTeam {
	TeamSkin,
	Name[ 128 ],
	InGameColor,
	OutColor,
	TeamRole,
	TeamRounds,
	GamePlayers
}
new iTeam[MAX_TEAMS][eTeam];

// player info
enum ePlayer {
	InGame,
	Team,
	Nickname[ 24 ],
	GunmenuStep,
	GunMenuW1,
	GunMenuW2,
	RKills,
	RDamage,
	Kills,
	Damage,
	bool:Spawned,
	PlayerHit,
	Hits,
	TotalAmount
}
new iPlayer[MAX_PLAYERS][ePlayer];
new pClassid[MAX_PLAYERS];

// gun menu
enum {
    GUNMENU_PART_1,
    GUNMENU_PART_2,
    GUNMENU_PART_CONFIRM
}

enum eGunMenu {
	Weaponname[ 24 ],
	Weaponid,
	slot
}

new iGunMenu_part1[][eGunMenu] =
{
	{ "Deagle", 	24, 2 },
	{ "Shotgun", 	25, 3 },
	{ "M4", 		31, 5 },
	{ "Spas12",     27, 3 },
	{ "Sniper", 	34, 6 }
};

new iGunMenu_part2[][eGunMenu] =
{
	{ "Shotgun", 	25, 3 },
	{ "Mp5", 		29, 4 },
	{ "Ak47", 		30, 5 },
	{ "Rifle", 		33, 6 },
	{ "Silenced", 	23, 2 }
};

// labels
//veh
new Text3D:VehLabel[MAX_VEHICLES];


main()
{
	print("\n----------------------------------");
	print(" Lite A/D v"#GAME_VERSION);
	print("----------------------------------\n");
}

forward LoadTeams(tag[], identifier[], text[]);
public LoadTeams(tag[], identifier[], text[]) {
	if(!strcmp(tag, "teama")) {
	    if(!strcmp(identifier, "skin")) iTeam[TEAM_A][TeamSkin] = strval(text);
	    if(!strcmp(identifier, "gamecolor")) iTeam[TEAM_A][InGameColor] = strval(text);
	    if(!strcmp(identifier, "outcolor")) iTeam[TEAM_A][OutColor] = strval(text);
	    if(!strcmp(identifier, "Name", true)) {
			strins(iTeam[TEAM_A][Name], text, 0);
		}
	}
	else if(!strcmp(tag, "teamb")) {
	    if(!strcmp(identifier, "skin")) iTeam[TEAM_B][TeamSkin] = strval(text);
	    if(!strcmp(identifier, "gamecolor")) iTeam[TEAM_B][InGameColor] = strval(text);
	    if(!strcmp(identifier, "outcolor")) iTeam[TEAM_B][OutColor] = strval(text);
	    if(!strcmp(identifier, "Name", true)) {
			strins(iTeam[TEAM_B][Name], text, 0);
		}
	}
	else if(!strcmp(tag, "teamref")) {
	    if(!strcmp(identifier, "skin")) iTeam[TEAM_REF][TeamSkin] = strval(text);
	    if(!strcmp(identifier, "outcolor")) iTeam[TEAM_REF][OutColor] = strval(text);
	    if(!strcmp(identifier, "Name", true)) {
			strins(iTeam[TEAM_REF][Name], text, 0);
			iTeam[TEAM_REF][TeamRole] = REFEREE;
		}
	}
}

forward LoadConfig(identifier[], text[]);
public LoadConfig(identifier[], text[]) {
	if(!strcmp(identifier, "roundtime")) gConfig[ConfigTime] = strval(text);
	else if(!strcmp(identifier, "cptime")) gConfig[ConfigCPTime] = strval(text);
	else if(!strcmp(identifier, "usecp")) gConfig[UseCp] = bool:strval(text);
	else if(!strcmp(identifier, "totalrounds")) gConfig[TotalRounds] = strval(text);
	else if(!strcmp(identifier, "lobby")) {
		new ex[ 4 ][ 69 ];
	    strExplode(text, ",", ex);
	    
		gConfig[Lobby][0] = floatstr(ex[0]);
		gConfig[Lobby][1] = floatstr(ex[1]);
		gConfig[Lobby][2] = floatstr(ex[2]);
		gConfig[Lobby][3] = floatstr(ex[3]);
	}
}

stock LoadTextdraws() {
	TextDraw_RoundStats[0] = TextDrawCreate(642.000000, 435.000000, "_");
	TextDrawBackgroundColor(TextDraw_RoundStats[0], 255);
	TextDrawFont(TextDraw_RoundStats[0], 1);
	TextDrawLetterSize(TextDraw_RoundStats[0], 0.500000, 1.300000);
	TextDrawColor(TextDraw_RoundStats[0], -1);
	TextDrawSetOutline(TextDraw_RoundStats[0], 0);
	TextDrawSetProportional(TextDraw_RoundStats[0], 1);
	TextDrawSetShadow(TextDraw_RoundStats[0], 1);
	TextDrawUseBox(TextDraw_RoundStats[0], 1);
	TextDrawBoxColor(TextDraw_RoundStats[0], 136);
	TextDrawTextSize(TextDraw_RoundStats[0], -3.000000, 0.000000);

	TextDraw_RoundStats[1] = TextDrawCreate(320.000000, 435.000000, "| ~y~Lobby~w~ |");
	TextDrawAlignment(TextDraw_RoundStats[1], 2);
	TextDrawBackgroundColor(TextDraw_RoundStats[1], 255);
	TextDrawFont(TextDraw_RoundStats[1], 1);
	TextDrawLetterSize(TextDraw_RoundStats[1], 0.500000, 1.000000);
	TextDrawColor(TextDraw_RoundStats[1], -1);
	TextDrawSetOutline(TextDraw_RoundStats[1], 0);
	TextDrawSetProportional(TextDraw_RoundStats[1], 1);
	TextDrawSetShadow(TextDraw_RoundStats[1], 1);

	TextDraw_RoundStats[2] = TextDrawCreate(60.000000, 435.000000, "~b~~h~s7~w~ (~y~0~w~)");
	TextDrawBackgroundColor(TextDraw_RoundStats[2], 255);
	TextDrawFont(TextDraw_RoundStats[2], 1);
	TextDrawLetterSize(TextDraw_RoundStats[2], 0.500000, 1.000000);
	TextDrawColor(TextDraw_RoundStats[2], -1);
	TextDrawSetOutline(TextDraw_RoundStats[2], 0);
	TextDrawSetProportional(TextDraw_RoundStats[2], 1);
	TextDrawSetShadow(TextDraw_RoundStats[2], 1);

	TextDraw_RoundStats[3] = TextDrawCreate(580.000000, 435.000000, "~r~~h~s72~w~ (~y~0~w~)");
	TextDrawAlignment(TextDraw_RoundStats[3], 3);
	TextDrawBackgroundColor(TextDraw_RoundStats[3], 255);
	TextDrawFont(TextDraw_RoundStats[3], 1);
	TextDrawLetterSize(TextDraw_RoundStats[3], 0.500000, 1.000000);
	TextDrawColor(TextDraw_RoundStats[3], -1);
	TextDrawSetOutline(TextDraw_RoundStats[3], 0);
	TextDrawSetProportional(TextDraw_RoundStats[3], 1);
	TextDrawSetShadow(TextDraw_RoundStats[3], 1);

	TextDraw_RoundStats[4] = TextDrawCreate(7.000000, 435.000000, "hud:radar_enemyAttack");
	TextDrawBackgroundColor(TextDraw_RoundStats[4], 255);
	TextDrawFont(TextDraw_RoundStats[4], 4);
	TextDrawLetterSize(TextDraw_RoundStats[4], 0.500000, 1.000000);
	TextDrawColor(TextDraw_RoundStats[4], -1);
	TextDrawSetOutline(TextDraw_RoundStats[4], 0);
	TextDrawSetProportional(TextDraw_RoundStats[4], 1);
	TextDrawSetShadow(TextDraw_RoundStats[4], 1);
	TextDrawUseBox(TextDraw_RoundStats[4], 1);
	TextDrawBoxColor(TextDraw_RoundStats[4], 255);
	TextDrawTextSize(TextDraw_RoundStats[4], 21.000000, 12.000000);

	TextDraw_RoundStats[5] = TextDrawCreate(616.000000, 435.000000, "hud:radar_enemyAttack");
	TextDrawBackgroundColor(TextDraw_RoundStats[5], 255);
	TextDrawFont(TextDraw_RoundStats[5], 4);
	TextDrawLetterSize(TextDraw_RoundStats[5], 0.500000, 1.000000);
	TextDrawColor(TextDraw_RoundStats[5], -1);
	TextDrawSetOutline(TextDraw_RoundStats[5], 0);
	TextDrawSetProportional(TextDraw_RoundStats[5], 1);
	TextDrawSetShadow(TextDraw_RoundStats[5], 1);
	TextDrawUseBox(TextDraw_RoundStats[5], 1);
	TextDrawBoxColor(TextDraw_RoundStats[5], 255);
	TextDrawTextSize(TextDraw_RoundStats[5], 21.000000, 12.000000);
	
	print("Textdraw loaded");
}

stock CreateTextDrawForPlayers(playerid) {
	TD_Player_Damages[0] = CreatePlayerTextDraw(playerid, 140.000000, 360.000000, "s7.nickname / -100 hp / 2 hits");
	PlayerTextDrawBackgroundColor(playerid, TD_Player_Damages[0], 255);
	PlayerTextDrawFont(playerid, TD_Player_Damages[0], 1);
	PlayerTextDrawLetterSize(playerid, TD_Player_Damages[0], 0.300000, 1.000000);
	PlayerTextDrawColor(playerid, TD_Player_Damages[0], 16711935);
	PlayerTextDrawSetOutline(playerid, TD_Player_Damages[0], 0);
	PlayerTextDrawSetProportional(playerid, TD_Player_Damages[0], 1);
	PlayerTextDrawSetShadow(playerid, TD_Player_Damages[0], 1);

	TD_Player_Damages[1] = CreatePlayerTextDraw(playerid, 470.000000, 360.000000, "s7.nickname / -100 hp / 2 hits");
	PlayerTextDrawBackgroundColor(playerid, TD_Player_Damages[1], 255);
	PlayerTextDrawFont(playerid, TD_Player_Damages[1], 1);
	PlayerTextDrawLetterSize(playerid, TD_Player_Damages[1], 0.300000, 1.000000);
	PlayerTextDrawColor(playerid, TD_Player_Damages[1], -16776961);
	PlayerTextDrawSetOutline(playerid, TD_Player_Damages[1], 0);
	PlayerTextDrawSetProportional(playerid, TD_Player_Damages[1], 1);
	PlayerTextDrawSetShadow(playerid, TD_Player_Damages[1], 1);
	
	printf("Player-Textdraws for playerid %d created", playerid);
}

stock LoadBases() {
	new
	    loaded = 0
	;
	for(new i = 0; i < MAX_BASES; i++) {
	    if(fexist(BaseFile(i))) {
	        INI_ParseFile(BaseFile(i), "LoadBase", .bExtra = true, .extra = i);
			iBases[i][Exist] = true;
			loaded++;
	    }
		else {
			iBases[i][Exist] = false;
		}
	}
	printf("Bases loaded (%d/%d)", loaded, MAX_BASES);
}

stock LoadArenes() {
	new
	    loaded = 0
	;
	for(new i = 0; i < MAX_ARENE; i++) {
	    if(fexist(ArenaFile(i))) {
	        INI_ParseFile(ArenaFile(i), "LoadArene", .bExtra = true, .extra = i);
			iArene[i][Exist] = true;
			loaded++;
	    }
		else {
			iArene[i][Exist] = false;
		}
	}
	printf("Arene loaded (%d/%d)", loaded, MAX_ARENE);
}

forward LoadBase(baseid, identifier[], text[]);
public LoadBase(baseid, identifier[], text[]) {
	new ex[ 3 ][ 69 ];
	if(!strcmp(identifier, "T1_0")) { //att
	    strExplode(text, ",", ex);

		iBases[baseid][SpawnAtt][0] = floatstr(ex[0]);
		iBases[baseid][SpawnAtt][1] = floatstr(ex[1]);
		iBases[baseid][SpawnAtt][2] = floatstr(ex[2]);
	}
	else if(!strcmp(identifier, "T2_0")) { // def
	    strExplode(text, ",", ex);
	    
		iBases[baseid][SpawnDef][0] = floatstr(ex[0]);
		iBases[baseid][SpawnDef][1] = floatstr(ex[1]);
		iBases[baseid][SpawnDef][2] = floatstr(ex[2]);
	}
	else if(!strcmp(identifier, "home")) {
	    strExplode(text, ",", ex);
	    
		iBases[baseid][Checkpoint][0] = floatstr(ex[0]);
  		iBases[baseid][Checkpoint][1] = floatstr(ex[1]);
    	iBases[baseid][Checkpoint][2] = floatstr(ex[2]);
	}
	else if(!strcmp(identifier, "Interior")) {
		iBases[baseid][Interior] = strval(text);
	}
}

forward LoadArene(baseid, identifier[], text[]);
public LoadArene(baseid, identifier[], text[]) {
	new ex[ 3 ][ 69 ];
	if(!strcmp(identifier, "T0")||!strcmp(identifier, "T1_0")) { //att
	    strExplode(text, ",", ex);

		iArene[baseid][SpawnAtt][0] = floatstr(ex[0]);
		iArene[baseid][SpawnAtt][1] = floatstr(ex[1]);
		iArene[baseid][SpawnAtt][2] = floatstr(ex[2]);
	}
	else if(!strcmp(identifier, "T1")||!strcmp(identifier, "T2_0")) { // def
	    strExplode(text, ",", ex);

		iArene[baseid][SpawnDef][0] = floatstr(ex[0]);
		iArene[baseid][SpawnDef][1] = floatstr(ex[1]);
		iArene[baseid][SpawnDef][2] = floatstr(ex[2]);
	}
	else if(!strcmp(identifier, "home")) {
	    strExplode(text, ",", ex);

		iArene[baseid][Center][0] = floatstr(ex[0]);
  		iArene[baseid][Center][1] = floatstr(ex[1]);
    	iArene[baseid][Center][2] = floatstr(ex[2]);
	}
	else if(!strcmp(identifier, "Interior")) {
		iArene[baseid][Interior] = strval(text);
	}
}

stock LoadConf() {
	if(fexist(ConfigFile)) {
	    INI_ParseFile(ConfigFile, "LoadConfig");
	    print("Config loaded");
	}
	else print("Error: LoadConf no file");
}

stock LoadConfTeam() {
	if(fexist(TeamFile)) {
	    INI_ParseFile(TeamFile, "LoadTeams", .bPassTag = true);
	    print("Team loaded");
	}
	else print("Error: LoadConfTeam no file");
}

public OnGameModeInit() {
	UsePlayerPedAnims();
	LoadTextdraws();
	LoadConf();
	LoadConfTeam();
	LoadBases();
	LoadArenes();
	TeamSwaps();
	
	UpdateTextdrawPart(TD_PART_TEAMA);
	UpdateTextdrawPart(TD_PART_TEAMB);
	UpdateTextdrawPart(TD_PART_CENTER);
	
	SetGameModeText("Lite A/D v"#GAME_VERSION);
	
	AddPlayerClass(iTeam[TEAM_A][TeamSkin], gConfig[Lobby][0], gConfig[Lobby][1], gConfig[Lobby][2], gConfig[Lobby][3], 0, 0, 0, 0, 0, 0);
	AddPlayerClass(iTeam[TEAM_B][TeamSkin], gConfig[Lobby][0], gConfig[Lobby][1], gConfig[Lobby][2], gConfig[Lobby][3], 0, 0, 0, 0, 0, 0);
	AddPlayerClass(iTeam[TEAM_REF][TeamSkin], gConfig[Lobby][0], gConfig[Lobby][1], gConfig[Lobby][2], gConfig[Lobby][3], 0, 0, 0, 0, 0, 0);
	return 1;
}

public OnGameModeExit()
{
	return 1;
}

public OnPlayerRequestClass(playerid, classid) {
	pClassid[playerid] = classid + 1;
	
	SetPlayerPos(playerid, 2119.8633,-1195.8148,23.8356);
	SetPlayerFacingAngle(playerid, 27.4443);
	SetPlayerCameraPos(playerid, 2118.0898,-1193.0012,23.7812);
	SetPlayerCameraLookAt(playerid, 2119.8633,-1195.8148,23.8356);
	return 1;
}

public OnPlayerConnect(playerid) {
    CreateTextDrawForPlayers(playerid);
	GetPlayerName(playerid, iPlayer[playerid][Nickname], 24);
	SendClientMessageToAll(0x21C131AA, "** {00FF19}%s{21C131} has joined the server.", iPlayer[playerid][Nickname]);
	return 1;
}

public OnPlayerDisconnect(playerid, reason) {
	SendClientMessageToAll(0xDA2626AA, "** {FF0000}%s{DA2626} left the server.", iPlayer[playerid][Nickname]);
	if(iPlayer[playerid][InGame]){
    	RemovePlayerFromBase(playerid);
	}
	return 1;
}

public OnPlayerSpawn(playerid)
{
	iPlayer[playerid][Spawned] = true;
	SetPlayerHealth(playerid, 100.0);
	SetPlayerArmour(playerid, 100.0);
	for(new i = 0; i < sizeof(TextDraw_RoundStats); i++) {
	    TextDrawShowForPlayer(playerid, TextDraw_RoundStats[i]);
	}
	if(iPlayer[playerid][InGame]) {
	    SetPlayerInterior(playerid, iBases[StartedBase][Interior]);
	    SetPlayerColor(playerid, iTeam[iPlayer[playerid][Team]][InGameColor]);
	    ResetPlayerWeapons(playerid);
	    if(iPlayer[playerid][GunMenuW1] != -1) {
	      	GivePlayerWeapon(playerid, iGunMenu_part1[iPlayer[playerid][GunMenuW1]][Weaponid], 9999);
	   		GivePlayerWeapon(playerid, iGunMenu_part2[iPlayer[playerid][GunMenuW2]][Weaponid], 9999);
		}
	}
	return 1;
}

public OnPlayerDeath(playerid, killerid, reason)
{
    iPlayer[playerid][Spawned] = false;
	if(iPlayer[playerid][InGame]) {
	    if(iPlayer[killerid][InGame]) {
	        iPlayer[killerid][RKills] ++;
	    }
	    RemovePlayerFromBase(playerid);
	}
	return 1;
}


public OnPlayerStateChange(playerid, newstate, oldstate)
{
	return 1;
}

public OnPlayerRequestSpawn(playerid) {
	switch(pClassid[playerid]) {
	    case TEAM_A: {
	        iPlayer[playerid][Team] = TEAM_A;
			SendClientMessageToAll(0xC3C60BAA, "** {FBFF00}%s{C3C60B} spawned as {FBFF00}%s{C3C60B} ({FBFF00}%s{C3C60B})", iPlayer[playerid][Nickname], iTeam[TEAM_A][Name], GetRoleName(iTeam[TEAM_A][TeamRole]));
		}
		case TEAM_B: {
		    iPlayer[playerid][Team] = TEAM_B;
			SendClientMessageToAll(0xC3C60BAA, "** {FBFF00}%s{C3C60B} spawned as {FBFF00}%s{C3C60B} ({FBFF00}%s{C3C60B})", iPlayer[playerid][Nickname], iTeam[TEAM_B][Name], GetRoleName(iTeam[TEAM_B][TeamRole]));
		}
		case TEAM_REF: {
		    iPlayer[playerid][Team] = TEAM_REF;
			SendClientMessageToAll(0xC3C60BAA, "** {FBFF00}%s{C3C60B} spawned as {FBFF00}%s{C3C60B} ({FBFF00}%s{C3C60B})", iPlayer[playerid][Nickname], iTeam[TEAM_REF][Name], GetRoleName(iTeam[TEAM_REF][TeamRole]));
		}
	}
	return 1;
}

public OnVehicleStreamIn(vehicleid, forplayerid)
{
    if(GetVehicleVirtualWorld(vehicleid) == GAME_WORLD) {
		if(iTeam[iPlayer[forplayerid][Team]][TeamRole] == DEFENDERS) {
		    SetVehicleParamsForPlayer(vehicleid, forplayerid, 0, 1);
		}
    }
    return 1;
}

public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
	return 1;
}

public OnPlayerTakeDamage(playerid, issuerid, Float: amount, weaponid) {
	if(gConfig[RoundStarted]) {
	    SetTimerEx("Delay_TakeDamage", 500, 0, "i", playerid);
	}
	    //TD_Player_Damages[0] TD_Player_Damages[1]
	if(!iPlayer[playerid][Spawned]) return 1;
 	new szHits[ 128 ];
  	if(issuerid != INVALID_PLAYER_ID) {
  	
  	    if(iPlayer[issuerid][PlayerHit] != playerid) {
  	        iPlayer[issuerid][Hits] = 0;
  	        iPlayer[issuerid][TotalAmount] = 0;
  	        iPlayer[issuerid][PlayerHit] = INVALID_PLAYER_ID;
  	    }
  	
  	    iPlayer[issuerid][Hits] ++;
		iPlayer[issuerid][TotalAmount] += floatround(amount);
		iPlayer[issuerid][PlayerHit] = playerid;

  	    if(iPlayer[playerid][PlayerHit] != issuerid) {
  	        iPlayer[playerid][Hits] = 0;
  	        iPlayer[playerid][TotalAmount] = 0;
  	        iPlayer[playerid][PlayerHit] = INVALID_PLAYER_ID;
  	    }

  	    iPlayer[playerid][Hits] ++;
		iPlayer[playerid][TotalAmount] += floatround(amount);
		iPlayer[playerid][PlayerHit] = issuerid;

  	
   		new szWeap[ 24 ];
     	GetWeaponName(weaponid, szWeap, 24);
      	format(szHits, sizeof szHits, "%s / -%d HP (x%d) / %s", iPlayer[issuerid][Nickname], iPlayer[issuerid][TotalAmount], iPlayer[playerid][Hits], szWeap);
	        
		PlayerTextDrawSetString(playerid, TD_Player_Damages[1], szHits);
		PlayerTextDrawShow(playerid, TD_Player_Damages[1]);

      	format(szHits, sizeof szHits, "%s / +%d HP (x%d) / %s", iPlayer[playerid][Nickname], floatround(amount), iPlayer[issuerid][Hits], szWeap);

		PlayerTextDrawSetString(issuerid, TD_Player_Damages[1], szHits);
		PlayerTextDrawShow(issuerid, TD_Player_Damages[0]);
		
		SetTimerEx("PlayerDmg_Hide", 3000, 0, "i", issuerid);

  	}
   	else {
  	    if(iPlayer[playerid][PlayerHit] != issuerid) {
  	        iPlayer[playerid][Hits] = 0;
  	        iPlayer[playerid][TotalAmount] = 0;
  	        iPlayer[playerid][PlayerHit] = INVALID_PLAYER_ID;
  	    }

  	    iPlayer[playerid][Hits] ++;
		iPlayer[playerid][TotalAmount] += floatround(amount);
		iPlayer[playerid][PlayerHit] = issuerid;
		
    	new szWeap[ 24 ];
     	GetWeaponName(weaponid, szWeap, 24);
      	format(szHits, sizeof szHits, "%s / -%d (x%d) HP", szWeap, iPlayer[playerid][TotalAmount], iPlayer[playerid][Hits]);

		PlayerTextDrawSetString(playerid, TD_Player_Damages[1], szHits);
		PlayerTextDrawShow(playerid, TD_Player_Damages[1]);
    }
    SetTimerEx("PlayerDmg_Hide", 3000, 0, "i", playerid);
	return 1;
}

forward PlayerDmg_Hide(playerid);
public PlayerDmg_Hide(playerid) {
	PlayerTextDrawHide(playerid, TD_Player_Damages[0]);
	PlayerTextDrawHide(playerid, TD_Player_Damages[1]);
    iPlayer[playerid][Hits] = 0;
  	iPlayer[playerid][TotalAmount] = 0;
  	iPlayer[playerid][PlayerHit] = INVALID_PLAYER_ID;
}

forward Delay_TakeDamage(playerid);
public Delay_TakeDamage(playerid) {
	if(iPlayer[playerid][Team]==TEAM_A) UpdateTextdrawPart(TD_PART_TEAMA);
	if(iPlayer[playerid][Team]==TEAM_B) UpdateTextdrawPart(TD_PART_TEAMB);
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	switch(dialogid) {
	    case DIALOG_SWITCH: {
	        new t = listitem + 1;
	        iPlayer[playerid][Team] = t;
	        SetSpawnInfo(playerid, playerid, iTeam[t][TeamSkin], gConfig[Lobby][0], gConfig[Lobby][1], gConfig[Lobby][2], 0, 0, 0, 0, 0, 0, 0);
	        SendClientMessageToAll(0xC3C60BAA, "** {FBFF00}%s{C3C60B} switched as {FBFF00}%s{C3C60B} ({FBFF00}%s{C3C60B})", iPlayer[playerid][Nickname], iTeam[t][Name], GetRoleName(iTeam[t][TeamRole]));
			SpawnPlayer(playerid);
		}
		case DIALOG_GUNMENU_STEP1: {
		    if(iPlayer[playerid][GunMenuW2] != -1) {
			    if(iGunMenu_part1[listitem][slot] == iGunMenu_part2[iPlayer[playerid][GunMenuW2]][slot]) {
			        SendClientMessage(playerid, red, "You already have a weapon in the same slot");
			        return ShowGunMenu(playerid, GUNMENU_PART_1);
			    }
		    }
		    iPlayer[playerid][GunMenuW1] = listitem;
		    new str[ 128 ];
		    format(str, sizeof str, "~p~1. %s", iGunMenu_part1[listitem][Weaponname]);
		    PlayerTextDrawSetString(playerid, TD_Gunmenu_Weapons[2], str);
		    
		    ShowGunMenu(playerid, GUNMENU_PART_2);
		}
		case DIALOG_GUNMENU_STEP2: {
		    if(!response) ShowGunMenu(playerid, GUNMENU_PART_1);
		    if(iPlayer[playerid][GunMenuW1] != -1) {
			    if(iGunMenu_part2[listitem][slot] == iGunMenu_part1[iPlayer[playerid][GunMenuW1]][slot]) {
			        SendClientMessage(playerid, red, "You already have a weapon in the same slot");
			        return ShowGunMenu(playerid, GUNMENU_PART_2);
			    }
			}
		    iPlayer[playerid][GunMenuW2] = listitem;
		    new str[ 128 ];
		    format(str, sizeof str, "~p~2. %s", iGunMenu_part2[listitem][Weaponname]);
		    PlayerTextDrawSetString(playerid, TD_Gunmenu_Weapons[3], str);
		    
		    ShowGunMenu(playerid, GUNMENU_PART_CONFIRM);
		}
		case DIALOG_GUNMENU_STEPCONFIRM: {
		    if(!response) {
		        iPlayer[playerid][GunMenuW1] = -1;
		        iPlayer[playerid][GunMenuW1] = -1;
		        PlayerTextDrawSetString(playerid, TD_Gunmenu_Weapons[2], "1. _");
		        PlayerTextDrawSetString(playerid, TD_Gunmenu_Weapons[3], "2. _");
				ShowGunMenu(playerid, GUNMENU_PART_1);
			}
			switch(listitem) {
			    case 0: {
			        ResetPlayerWeapons(playerid);
			        GivePlayerWeapon(playerid, iGunMenu_part1[iPlayer[playerid][GunMenuW1]][Weaponid], 9999);
			        GivePlayerWeapon(playerid, iGunMenu_part2[iPlayer[playerid][GunMenuW2]][Weaponid], 9999);
			        
			        PlayerTextDrawDestroy(playerid, TD_Gunmenu_Weapons[0]);
			        PlayerTextDrawDestroy(playerid, TD_Gunmenu_Weapons[1]);
			        PlayerTextDrawDestroy(playerid, TD_Gunmenu_Weapons[2]);
			        PlayerTextDrawDestroy(playerid, TD_Gunmenu_Weapons[3]);
			        
			        new w1[ 24 ], w2[ 24 ];
			        GetWeaponName(iGunMenu_part1[iPlayer[playerid][GunMenuW1]][Weaponid], w1, 24);
		    	    GetWeaponName(iGunMenu_part2[iPlayer[playerid][GunMenuW2]][Weaponid], w2, 24);

			        foreach(new i:Player) {
			            if(iPlayer[i][Team] == iPlayer[playerid][Team]) {
			                SendClientMessage(i, iTeam[iPlayer[playerid][Team]][InGameColor], ">> %s chose the weapons %s and %s", iPlayer[playerid][Nickname], w1, w2);
			            }
			        }
			    }
			    case 1: {
			        iPlayer[playerid][GunMenuW1] = 0;
			        iPlayer[playerid][GunMenuW1] = 0;
			        PlayerTextDrawSetString(playerid, TD_Gunmenu_Weapons[2], "1. _");
			        PlayerTextDrawSetString(playerid, TD_Gunmenu_Weapons[3], "2. _");
					ShowGunMenu(playerid, GUNMENU_PART_1);
			    }
			}
		}
		case DIALOG_VEHLIST: {
		    if(!response) return 1;
		    for(new i = 0; i < 212; i++) {
		        if(i == listitem) {
				    new
				        Float:x,
				        Float:y,
				        Float:z,
				        Float:a
					;
					GetPlayerPos(playerid, x, y, z);
					GetPlayerFacingAngle(playerid, a);

				    new veh = CreateVehicleEx(i+400, x, y, z, a, -1, -1, -1, GetPlayerVirtualWorld(playerid));
				    SetVehicleVirtualWorld(veh, GetPlayerVirtualWorld(playerid));
				    PutPlayerInVehicle(playerid, veh, 0);

				    SendClientMessage(playerid, 0x3C77DCAA, "Spawned a {005EFF}%s", aVehicleNames[i]);
				    break;
      			}
		    }
		}
	}
	return 1;
}

public OnPlayerClickPlayer(playerid, clickedplayerid, source)
{
	return 1;
}

// ******************************************************************************** //
// Commands
COMMAND:help(playerid, params[]) {
	ShowPlayerDialog(playerid, DIALOG_HELP, DIALOG_STYLE_MSGBOX, "Help box", "{C9CC32}Welcome to {FBFF00}Lite A/D v"#GAME_VERSION"\n{C9CC32}Gamemode created to be as simple as possible and fast, but without losing quality and beauty of the gamemode A / D.\nThe gamemode is still in {FBFF00}beta{C9CC32} and is open source visit this page to download it or report a bug: {FBFF00}http://code.google.com/p/litead/", "Close", "");
	return 1;
}

COMMAND:setrounds(playerid, params[]) {
	if(isnull(params)) {
	    return SendClientMessage(playerid, red, "Use /setrounds [rounds]");
	}
	if(strval(params) < 1) {
	    return SendClientMessage(playerid, red, "Use /setrounds [rounds] - Invalid rounds");
	}
	new r = strval(params);
	gConfig[TotalRounds] = r;
	UpdateTextdrawPart(TD_PART_CENTER);
	SendClientMessageToAll(0xC9CC32AA, "Admin {FBFF00}%s{C9CC32} set rounds limit to {FBFF00}%d", iPlayer[playerid][Nickname], r);
	return 1;
}

COMMAND:teamrounds(playerid, params[]) {
	new ex[ 2 ][ 128 ];
	strExplode(params, " ", ex);
	if(isnull(ex[ 0 ])) {
	    return SendClientMessage(playerid, red, "Use /teamrounds [team] [rounds]");
	}
	new team = strval( ex[ 0 ] );
	if( team != TEAM_A && team != TEAM_B )return SendClientMessage(playerid, red, "Invalid team");
	if(isnull(ex[ 1 ])) {
	    return SendClientMessage(playerid, red, "Use /teamrounds [team] [rounds]");
	}
	new rounds = strval( ex[ 1 ] );
	if(rounds < 0)return SendClientMessage(playerid, red, "Invalid rounds");
	iTeam[team][TeamRounds] = rounds;
	SendClientMessageToAll(0xC9CC32AA, "Admin {FBFF00}%s{C9CC32} set team {FBFF00}%s{C9CC32} scores to {FBFF00}%d", iPlayer[playerid][Nickname], iTeam[team][Name], rounds);
	gConfig[CurrentRound] = (iTeam[TEAM_A][TeamRounds]+iTeam[TEAM_B][TeamRounds]);

	UpdateTextdrawPart(TD_PART_TEAMA);
	UpdateTextdrawPart(TD_PART_TEAMB);
	UpdateTextdrawPart(TD_PART_CENTER);
	return 1;
}

COMMAND:startbase(playerid, params[]) {
	if(isnull(params)) {
	    return SendClientMessage(playerid, red, "Use /startbase [id/-1 random]");
	}
	new id = strval(params);
	if(id == -1) {
	    do {
			id = random(MAX_BASES);
	    } while(!fexist(BaseFile(id)));
	    StartRound(
	        .id = id,
	        .player = playerid,
	        .random = 1
		);
	}
	else {
	    if(!fexist(BaseFile(id))) return SendClientMessage(playerid, red, "Invalid Base ID");
	    StartRound(
			.id = id,
			.player = playerid,
			.random = 0
		);
	}
	return 1;
}

COMMAND:kill(playerid, params[]) {
	SetPlayerHealth(playerid, 0.0);
	return 1;
}

COMMAND:switch(playerid, params[]) {
	new str[ 159 ];
	format(str, sizeof str, "Team %s (%s)\nTeam %s (%s)\nTeam %s (%s)",
		iTeam[TEAM_A][Name],
		GetRoleName(iTeam[TEAM_A][TeamRole]),
		iTeam[TEAM_B][Name],
		GetRoleName(iTeam[TEAM_B][TeamRole]),
		iTeam[TEAM_REF][Name],
		GetRoleName(iTeam[TEAM_REF][TeamRole])
	);
	ShowPlayerDialog(playerid, DIALOG_SWITCH, DIALOG_STYLE_LIST, "Team switch", str, "Switch", "Close");
	return 1;
}

COMMAND:test(playerid, params[]) {
	return EndRound(GetDefenders(), WINTYPE_TIMER);
}

COMMAND:resetscores(playerid, params[]) {
	if(!IsPlayerAdminEx(playerid)) return SendClientMessage(playerid, red, ADMIN_REQ);
	ResetScores();
	SendClientMessageToAll(0xDBD81AAA, "Admin {FFFB00}%s{DBD81A} reset scores", iPlayer[playerid][Nickname]);
	return 1;
}

COMMAND:v(playerid, params[]) {
	if(gConfig[RoundStarted]) {
	    if(iTeam[iPlayer[playerid][Team]][TeamRole] == DEFENDERS) return SendClientMessage(playerid, red, "Only attackers can spawn a vehicle");
		if(!IsPlayerInRangeOfPoint(playerid, 150.0, iBases[StartedBase][SpawnAtt][0], iBases[StartedBase][SpawnAtt][1], iBases[StartedBase][SpawnAtt][2])) return SendClientMessage(playerid, red, "You are too away from attackers spawn");
	}
    if(isnull(params)) {
        new szVehs[ 2024 ];
		for(new i = 0; i < 212; i++) {
		    format(szVehs, sizeof szVehs, "%s%s\n", szVehs, aVehicleNames[i]);
		}
		ShowPlayerDialog(playerid, DIALOG_VEHLIST, DIALOG_STYLE_LIST, "Veh List", szVehs, "Spawna", "Chiudi");
		return 1;
	}

	new idx = GetVehicleModelIDFromName(params);
	
	if(idx == -1) SendClientMessage(playerid, red, "Invalid veh");
	else {
	    new
	        Float:x,
	        Float:y,
	        Float:z,
	        Float:a
		;
		GetPlayerPos(playerid, x, y, z);
		GetPlayerFacingAngle(playerid, a);
		
	    new veh = CreateVehicleEx(idx, x, y, z, a, -1, -1, -1, GetPlayerVirtualWorld(playerid));
	    SetVehicleVirtualWorld(veh, GetPlayerVirtualWorld(playerid));
	    PutPlayerInVehicle(playerid, veh, 0);
	    
	    SendClientMessage(playerid, 0x3C77DCAA, "Spawned a {005EFF}%s", aVehicleNames[idx - 400]);

		if( gConfig[RoundStarted] ) {
			foreach(new i:Player) {
				if(iTeam[iPlayer[i][Team]][TeamRole] == DEFENDERS) {
				    SetVehicleParamsForPlayer(veh, i, 0, 1);
				}
			}
		}
	}
	return 1;
}

// ******************************************************************************** //

stock StartRound(id, player, random) {
    gConfig[CurrentRound]++;
    gConfig[RoundCPTime] = gConfig[ConfigCPTime];
    gConfig[RoundTime] = gConfig[ConfigTime];
    gConfig[RoundStarted] = true;
    StartedBase = id;
    
	if(random) {
	    if(player != INVALID_PLAYER_ID) {
	        SendClientMessageToAll(0x3F92CDAA, "* Base {0095FF}%d{3F92CD} started by {0095FF}%s{3F92CD} via random", id, iPlayer[player][Nickname]);
	    }
	    else {
	        SendClientMessageToAll(0x3F92CDAA, "* Base {0095FF}%d{3F92CD} started via random", id);
	    }
	}
	else {
	    if(player != INVALID_PLAYER_ID) {
	        SendClientMessageToAll(0x3F92CDAA, "* Base {0095FF}%d{3F92CD} started by {0095FF}%s{3F92CD}", id, iPlayer[player][Nickname]);
	    }
	    else {
	        SendClientMessageToAll(0x3F92CDAA, "* Base {0095FF}%d{3F92CD} started", id);
	    }
	}
	
	foreach(new i:Player) {
	    if(iPlayer[i][Team] == TEAM_NULL || iPlayer[i][Team] == TEAM_REF) continue;
	    AddPlayerInBase(i);
        InterpolateCameraPos(i, floatround(iBases[id][SpawnAtt][0]), floatround(iBases[id][SpawnAtt][1]), floatround(iBases[id][SpawnAtt][2]), floatround(iBases[id][Checkpoint][0]), floatround(iBases[id][Checkpoint][1]-5), floatround(iBases[id][Checkpoint][2]), 5000, CAMERA_CUT);
        InterpolateCameraLookAt(i, floatround(iBases[id][Checkpoint][0]), floatround(iBases[id][Checkpoint][1]), 40.0, floatround(iBases[id][Checkpoint][0]), floatround(iBases[id][Checkpoint][1]), floatround(iBases[id][Checkpoint][2]), 5000);
        PlayerPlaySound(i, 1187, 0.0, 0.0, 0.0);
	}
	
	SetTimer("RoundReady", 5000, 0);
	return 1;
}

// ******************************************************************************** //

stock ShowGunMenu(playerid, part) {
	switch(part) {
	    case GUNMENU_PART_1: {
	        new str[ 128 ];
	        for(new i = 0; i < sizeof(iGunMenu_part1); i++) {
	            format(str, sizeof str, "%s%s\n", str, iGunMenu_part1[i][Weaponname]);
	        }
	        ShowPlayerDialog(playerid, DIALOG_GUNMENU_STEP1, DIALOG_STYLE_LIST, "Gunmenu - Part1", str, "Choose", "");
	    }
		case GUNMENU_PART_2: {
	        new str[ 128 ];
	        for(new i = 0; i < sizeof(iGunMenu_part2); i++) {
	            format(str, sizeof str, "%s%s\n", str, iGunMenu_part2[i][Weaponname]);
	        }
	        ShowPlayerDialog(playerid, DIALOG_GUNMENU_STEP2, DIALOG_STYLE_LIST, "Gunmenu - Part2", str, "Choose", "Back");
		}
		case GUNMENU_PART_CONFIRM: {
		    ShowPlayerDialog(playerid, DIALOG_GUNMENU_STEPCONFIRM, DIALOG_STYLE_LIST, "Gunmenu - Confirm", "{2FFF00}> Confirm this weaponset\n{FF0000}< Back to First gunmenu", "Chose", "");
		}
	}
	return 1;
}

// ******************************************************************************** //

stock AddPlayerInBase(playerid) {
	iPlayer[playerid][GunMenuW1] = -1;
	iPlayer[playerid][GunMenuW2] = -1;
	new
	    team = iPlayer[playerid][Team]
	;
	if(iTeam[team][TeamRole] == ATTACKERS) {
	    SetSpawnInfo(playerid, team, iTeam[team][TeamSkin], iBases[StartedBase][SpawnAtt][0], iBases[StartedBase][SpawnAtt][1], iBases[StartedBase][SpawnAtt][2], 0.0, 0, 0, 0, 0, 0, 0);
	}
	else {
	    SetSpawnInfo(playerid, team, iTeam[team][TeamSkin], iBases[StartedBase][SpawnDef][0], iBases[StartedBase][SpawnDef][1], iBases[StartedBase][SpawnDef][2], 0.0, 0, 0, 0, 0, 0, 0);
	}
	SetPlayerCheckpoint(playerid, iBases[StartedBase][Checkpoint][0], iBases[StartedBase][Checkpoint][1], iBases[StartedBase][Checkpoint][2], 2.5);
	SpawnPlayer(playerid);
	
	UpdateTextdrawPart(TD_PART_TEAMA);
	UpdateTextdrawPart(TD_PART_TEAMB);
	
	ShowGunMenu(playerid, GUNMENU_PART_1);
	
	SetPlayerVirtualWorld(playerid, GAME_WORLD);
	iTeam[team][GamePlayers]++;
	iPlayer[playerid][InGame] = 1;
	
	TD_Gunmenu_Weapons[0] = CreatePlayerTextDraw(playerid, 400.000000, 138.000000, "-");
	PlayerTextDrawAlignment(playerid, TD_Gunmenu_Weapons[0], 3);
	PlayerTextDrawBackgroundColor(playerid, TD_Gunmenu_Weapons[0], 255);
	PlayerTextDrawFont(playerid, TD_Gunmenu_Weapons[0], 1);
	PlayerTextDrawLetterSize(playerid, TD_Gunmenu_Weapons[0], 12.700012, 39.000000);
	PlayerTextDrawColor(playerid, TD_Gunmenu_Weapons[0], -1);
	PlayerTextDrawSetOutline(playerid, TD_Gunmenu_Weapons[0], 0);
	PlayerTextDrawSetProportional(playerid, TD_Gunmenu_Weapons[0], 1);
	PlayerTextDrawSetShadow(playerid, TD_Gunmenu_Weapons[0], 1);

	TD_Gunmenu_Weapons[1] = CreatePlayerTextDraw(playerid, 311.000000, 339.000000, "~y~Weapons");
	PlayerTextDrawAlignment(playerid, TD_Gunmenu_Weapons[1], 2);
	PlayerTextDrawBackgroundColor(playerid, TD_Gunmenu_Weapons[1], 255);
	PlayerTextDrawFont(playerid, TD_Gunmenu_Weapons[1], 3);
	PlayerTextDrawLetterSize(playerid, TD_Gunmenu_Weapons[1], 0.500000, 1.000000);
	PlayerTextDrawColor(playerid, TD_Gunmenu_Weapons[1], -1);
	PlayerTextDrawSetOutline(playerid, TD_Gunmenu_Weapons[1], 0);
	PlayerTextDrawSetProportional(playerid, TD_Gunmenu_Weapons[1], 1);
	PlayerTextDrawSetShadow(playerid, TD_Gunmenu_Weapons[1], 1);

	TD_Gunmenu_Weapons[2] = CreatePlayerTextDraw(playerid, 264.000000, 352.000000, "~p~1. _");
	PlayerTextDrawBackgroundColor(playerid, TD_Gunmenu_Weapons[2], 255);
	PlayerTextDrawFont(playerid, TD_Gunmenu_Weapons[2], 0);
	PlayerTextDrawLetterSize(playerid, TD_Gunmenu_Weapons[2], 0.500000, 1.000000);
	PlayerTextDrawColor(playerid, TD_Gunmenu_Weapons[2], -1);
	PlayerTextDrawSetOutline(playerid, TD_Gunmenu_Weapons[2], 0);
	PlayerTextDrawSetProportional(playerid, TD_Gunmenu_Weapons[2], 1);
	PlayerTextDrawSetShadow(playerid, TD_Gunmenu_Weapons[2], 1);

	TD_Gunmenu_Weapons[3] = CreatePlayerTextDraw(playerid, 257.000000, 365.000000, "~p~2. _");
	PlayerTextDrawBackgroundColor(playerid, TD_Gunmenu_Weapons[3], 255);
	PlayerTextDrawFont(playerid, TD_Gunmenu_Weapons[3], 0);
	PlayerTextDrawLetterSize(playerid, TD_Gunmenu_Weapons[3], 0.500000, 1.000000);
	PlayerTextDrawColor(playerid, TD_Gunmenu_Weapons[3], -1);
	PlayerTextDrawSetOutline(playerid, TD_Gunmenu_Weapons[3], 0);
	PlayerTextDrawSetProportional(playerid, TD_Gunmenu_Weapons[3], 1);
	PlayerTextDrawSetShadow(playerid, TD_Gunmenu_Weapons[3], 1);
	
	PlayerTextDrawShow(playerid, TD_Gunmenu_Weapons[0]);
	PlayerTextDrawShow(playerid, TD_Gunmenu_Weapons[1]);
	PlayerTextDrawShow(playerid, TD_Gunmenu_Weapons[2]);
	PlayerTextDrawShow(playerid, TD_Gunmenu_Weapons[3]);
}

// ******************************************************************************** //

stock RemovePlayerFromBase(playerid) {
	iPlayer[playerid][InGame] = 0;
	SetPlayerVirtualWorld(playerid, NORMAL_WORLD);
	new team = iPlayer[playerid][Team];
	SetSpawnInfo(playerid, playerid, iTeam[team][TeamSkin], gConfig[Lobby][0], gConfig[Lobby][1], gConfig[Lobby][2], gConfig[Lobby][3], 0, 0, 0, 0, 0, 0);
	iPlayer[playerid][GunMenuW1] = -1;
	iPlayer[playerid][GunMenuW2] = -1;
	iTeam[team][GamePlayers]--;
	DisablePlayerCheckpoint(playerid);
	SpawnPlayer(playerid);
	if(iTeam[TEAM_A][GamePlayers] == 0) {
		EndRound(
		    .winner = TEAM_B,
			.wintype = WINTYPE_ELIMINAZIONE
	    );
	}
	else if(iTeam[TEAM_B][GamePlayers] == 0) {
		EndRound(
		    .winner = TEAM_A,
			.wintype = WINTYPE_ELIMINAZIONE
	    );
	}
	else if(iTeam[TEAM_A][GamePlayers] == 0 && iTeam[TEAM_B][GamePlayers] == 0) {
		EndRound(
		    .winner = TEAM_NULL,
			.wintype = WINTYPE_ALLDEATH
	    );
	}
}

// ******************************************************************************** //

forward RoundReady();
public RoundReady() {
	foreach(new i:Player) {
	    if(!iPlayer[i][InGame]) continue;
	    SetPlayerHealth(i, 100.0);
	    SetPlayerArmour(i, 100.0);
	    SetCameraBehindPlayer(i);
	    PlayerPlaySound(i, 1098, 0.0, 0.0, 0.0);
	}
	SetTimer("MarksUpdate", 50, 0);
	
	UpdateTextdrawPart(TD_PART_TEAMA);
	UpdateTextdrawPart(TD_PART_TEAMB);
	UpdateTextdrawPart(TD_PART_CENTER);
	
	SetTimer("UpdateRound", 1000, 0);
}

// ******************************************************************************** //

forward UpdateRound();
public UpdateRound() {
	if(RoundPaused || !gConfig[RoundStarted]) return 1;
	if(gConfig[UseCp]) {
	    new att = 0;
		foreach(new i:Player) {
		    if(!IsPlayerInCheckpoint(i)) continue;
		    if(iTeam[iPlayer[i][Team]][TeamRole] == ATTACKERS) att = 1;
			else if(iTeam[iPlayer[i][Team]][TeamRole] == DEFENDERS) att = 0;
			
		}
		if(att) {
   			gConfig[RoundCPTime] --;
   			if(gConfig[RoundCPTime] < 1) {
   			    EndRound(
   			        .winner = GetAttackers(),
   			        .wintype = WINTYPE_CHECKPOINT
				);
   			}
		}
		else {
		    gConfig[RoundCPTime] = gConfig[ConfigCPTime];
		}
	}
	gConfig[RoundSecs] --;
	if(gConfig[RoundSecs] < 1) {
	    gConfig[RoundSecs] = 59;
	    gConfig[RoundTime] --;
	    if(gConfig[RoundTime] < 0) {
	        EndRound(
				.wintype = WINTYPE_TIMER,
				.winner  = GetDefenders()
			);
	    }
	}
	UpdateTextdrawPart(TD_PART_CENTER);
	return SetTimer("UpdateRound", 1000, 0);
}

// ******************************************************************************* //

stock EndRound(winner, wintype) {
	switch(wintype) {
		case WINTYPE_ENDING, WINTYPE_ALLDEATH: {
	        SendClientMessageToAll(0xA1E03BAA, "The round is finished.. Noone wins");
		}
		default: {
	        SendClientMessageToAll(0xA1E03BAA, "The round is finished.. Team {9DFF00}%s{A1E03B} wins for {9DFF00}%s", iTeam[winner][Name], szWinType(wintype));

			iTeam[winner][TeamRounds] ++;
			
            gConfig[CurrentRound] ++;
			new
			    szString[ 1024 ]
			;

            if( gConfig[CurrentRound] < gConfig[TotalRounds] ) {

				format(szString, sizeof(szString) , "\t\t\t\t%s %d:%d %s\n", iTeam[TEAM_A][Name], iTeam[TEAM_A][TeamRounds], iTeam[TEAM_B][TeamRounds], iTeam[TEAM_B][Name]);

	        	format(szString, sizeof(szString), "%sNickname\t\t\tKills\t\tDamage\n", szString);

				format(szString, sizeof(szString), "%s{5AA11F}Team {78D829}%s{5AA11F}:\n", szString, iTeam[TEAM_A][Name]);

				foreach(new i:Player) {
				    if(iPlayer[i][Team] != TEAM_A) continue;
				    if(strlen(iPlayer[i][Nickname]) < 12) {
				    	format(szString, sizeof(szString), "%s{626FDD}%s\t\t\t\t%d\t\t%d\n", szString, iPlayer[i][Nickname], iPlayer[i][RKills], iPlayer[i][RDamage]);
					}
					else {
				    	format(szString, sizeof(szString), "%s{626FDD}%s\t\t\t%d\t\t%d\n", szString, iPlayer[i][Nickname], iPlayer[i][RKills], iPlayer[i][RDamage]);
					}
				}

				format(szString, sizeof(szString), "%s{5AA11F}Team {78D829}%s{5AA11F}:\n", szString, iTeam[TEAM_B][Name]);

				foreach(new i:Player) {
				    if(iPlayer[i][Team] != TEAM_B) continue;
				    if(strlen(iPlayer[i][Nickname]) < 12) {
				    	format(szString, sizeof(szString), "%s{626FDD}%s\t\t\t\t%d\t\t%d\n", szString, iPlayer[i][Nickname], iPlayer[i][RKills], iPlayer[i][RDamage]);
					}
					else {
				    	format(szString, sizeof(szString), "%s{626FDD}%s\t\t\t%d\t\t%d\n", szString, iPlayer[i][Nickname], iPlayer[i][RKills], iPlayer[i][RDamage]);
					}
				}

				foreach(new i:Player) {
				    ShowPlayerDialog(i, DIALOG_FINALROUND, DIALOG_STYLE_LIST, "Round finished", szString, "Close", "");
				}

			}
			else {
			
			    SendClientMessageToAll(0x2CFC08AA, "Tutti i rounds sono stati giocati!");
			
			    if(iTeam[TEAM_A][TeamRounds]>iTeam[TEAM_B][TeamRounds]) {
					format(szString, sizeof(szString) , "\t\tCW/TCW Ended! {26FF00}%s{FFFFFF} win! Scores: {FF0000}%s %d:%d %s\n", iTeam[TEAM_A][Name], iTeam[TEAM_A][Name], iTeam[TEAM_A][TeamRounds], iTeam[TEAM_B][TeamRounds], iTeam[TEAM_B][Name]);
				}
				else if(iTeam[TEAM_A][TeamRounds]<iTeam[TEAM_B][TeamRounds]) {
					format(szString, sizeof(szString) , "\t\tCW/TCW Ended! {26FF00}%s{FFFFFF} win! Scores: {FF0000}%s %d:%d %s\n", iTeam[TEAM_B][Name], iTeam[TEAM_A][Name], iTeam[TEAM_A][TeamRounds], iTeam[TEAM_B][TeamRounds], iTeam[TEAM_B][Name]);
				}
				else {
					format(szString, sizeof(szString) , "\t\tCW/TCW Ended! {26FF00}Noone{FFFFFF} win! Scores: {FF0000}%s %d:%d %s\n", iTeam[TEAM_A][Name], iTeam[TEAM_A][TeamRounds], iTeam[TEAM_B][TeamRounds], iTeam[TEAM_B][Name]);
				}

	        	format(szString, sizeof(szString), "%sNickname\t\t\tKills\t\tDamage\n", szString);

				format(szString, sizeof(szString), "%s{5AA11F}Team {78D829}%s{5AA11F}:\n", szString, iTeam[TEAM_A][Name]);

				foreach(new i:Player) {
				    if(iPlayer[i][Team] != TEAM_A) continue;
				    if(strlen(iPlayer[i][Nickname]) < 12) {
				    	format(szString, sizeof(szString), "%s{626FDD}%s\t\t\t\t%d\t\t%d\n", szString, iPlayer[i][Nickname], iPlayer[i][Kills], iPlayer[i][Damage]);
					}
					else {
				    	format(szString, sizeof(szString), "%s{626FDD}%s\t\t\t%d\t\t%d\n", szString, iPlayer[i][Nickname], iPlayer[i][Kills], iPlayer[i][Damage]);
					}
				}

				format(szString, sizeof(szString), "%s{5AA11F}Team {78D829}%s{5AA11F}:\n", szString, iTeam[TEAM_B][Name]);

				foreach(new i:Player) {
				    if(iPlayer[i][Team] != TEAM_B) continue;
				    if(strlen(iPlayer[i][Nickname]) < 12) {
				    	format(szString, sizeof(szString), "%s{626FDD}%s\t\t\t\t%d\t\t%d\n", szString, iPlayer[i][Nickname], iPlayer[i][Kills], iPlayer[i][Damage]);
					}
					else {
				    	format(szString, sizeof(szString), "%s{626FDD}%s\t\t\t%d\t\t%d\n", szString, iPlayer[i][Nickname], iPlayer[i][Kills], iPlayer[i][Damage]);
					}
				}

				foreach(new i:Player) {
				    ShowPlayerDialog(i, DIALOG_FINALROUND, DIALOG_STYLE_LIST, "Clanwar finished", szString, "Close", "");
				}
			}
			
			TeamSwaps();
			
		}
	}
	foreach(new i:Player) {
	    if(!iPlayer[i][InGame]) continue;
	    iPlayer[i][InGame]  = 0;
	    iPlayer[i][Kills]   += iPlayer[i][RKills];
	    iPlayer[i][Damage]  += iPlayer[i][RDamage];
	    iPlayer[i][RKills]  = 0;
	    iPlayer[i][RDamage] = 0;
	    DisablePlayerCheckpoint(i);
		SetSpawnInfo(i, i, iTeam[iPlayer[i][Team]][TeamSkin], gConfig[Lobby][0], gConfig[Lobby][1], gConfig[Lobby][2], gConfig[Lobby][3], 0, 0, 0, 0, 0, 0);
		SpawnPlayer(i);
	}
	
	gConfig[RoundStarted] = false;
	
	UpdateTextdrawPart(TD_PART_TEAMA);
	UpdateTextdrawPart(TD_PART_TEAMB);
	UpdateTextdrawPart(TD_PART_CENTER);
	return 1;
}

// ******************************************************************************** //

stock szWinType(wintype) {
	new str[ 69 ];
	switch(wintype) {
	    case WINTYPE_TIMER: 		str = "Timer";
	    case WINTYPE_ELIMINAZIONE: 	str = "Eliminazione";
	    case WINTYPE_CHECKPOINT:    str = "Checkpoint";
	}
	return str;
}

// **************************************************************************** //

stock ResetScores() {
	foreach(new i:Player) {
	    iPlayer[i][Kills] = 0;
	    iPlayer[i][Damage] = 0;
	    iPlayer[i][RKills] = 0;
	    iPlayer[i][RDamage] = 0;
	}
	gConfig[CurrentRound] = 0;
	iTeam[TEAM_A][TeamRounds] = 0;
	iTeam[TEAM_B][TeamRounds] = 0;
	UpdateTextdrawPart(TD_PART_TEAMA);
	UpdateTextdrawPart(TD_PART_TEAMB);
	UpdateTextdrawPart(TD_PART_CENTER);
}

// **************************************************************************** //

stock IsPlayerAdminEx(playerid) { // this will be used for make level admins
	if(IsPlayerAdmin(playerid)) {
	    return 1;
	}
	return 0;
}

// ******************************************************************************** //

stock UpdateTextdrawPart(part) {
	if(part < TD_PART_TEAMA || part > TD_PART_CENTER) return print("Invalid PART passed");
	new
	    str[ 128 ]
	;
	switch(part) {
	    case TD_PART_TEAMA: {
	        if(gConfig[RoundStarted]) {
	            new Float:h, Float:a, totalife;
	            foreach(new i:Player) {
					if(!iPlayer[i][InGame]) continue;
					if(iPlayer[i][Team] != TEAM_A) continue;
	                GetPlayerHealth(i, h);
	                GetPlayerArmour(i, a);
	                totalife = floatround(h+a);
	            }
	            format(str, sizeof str, "~b~~h~%s~w~ (~g~~h~%d~w~) (~y~%d~w~)", iTeam[TEAM_A][Name], iTeam[TEAM_A][GamePlayers], totalife);
				TextDrawSetString(TextDraw_RoundStats[2], str);
				
				if( iTeam[TEAM_A][TeamRole] == ATTACKERS ) {
				    TextDrawSetString(TextDraw_RoundStats[4], "hud:radar_emmetGun");
				}
				else if( iTeam[TEAM_A][TeamRole] == DEFENDERS ) {
				    TextDrawSetString(TextDraw_RoundStats[4], "hud:radar_enemyAttack");
				}
				
			}
			else {
			    format(str, sizeof str, "~b~~h~%s~w~ (~y~%d~w~)", iTeam[TEAM_A][Name], iTeam[TEAM_A][TeamRounds]);
                TextDrawSetString(TextDraw_RoundStats[2], str);

				if( iTeam[TEAM_A][TeamRole] == ATTACKERS ) {
				    TextDrawSetString(TextDraw_RoundStats[4], "hud:radar_emmetGun");
				}
				else if( iTeam[TEAM_A][TeamRole] == DEFENDERS ) {
				    TextDrawSetString(TextDraw_RoundStats[4], "hud:radar_enemyAttack");
				}

			}
	    }
		case TD_PART_TEAMB: {
	        if(gConfig[RoundStarted]) {
	            new Float:h, Float:a, totalife;
	            foreach(new i:Player) {
					if(!iPlayer[i][InGame]) continue;
					if(iPlayer[i][Team] != TEAM_B) continue;
	                GetPlayerHealth(i, h);
	                GetPlayerArmour(i, a);
	                totalife = floatround(h+a);
	            }
	            format(str, sizeof str, "~r~~h~%s~w~ (~g~~h~%d~w~) (~y~%d~w~)", iTeam[TEAM_B][Name], iTeam[TEAM_B][GamePlayers], totalife);
				TextDrawSetString(TextDraw_RoundStats[3], str);

				if( iTeam[TEAM_B][TeamRole] == ATTACKERS ) {
				    TextDrawSetString(TextDraw_RoundStats[5], "hud:radar_emmetGun");
				}
				else if( iTeam[TEAM_B][TeamRole] == DEFENDERS ) {
				    TextDrawSetString(TextDraw_RoundStats[5], "hud:radar_enemyAttack");
				}

			}
			else {
			    format(str, sizeof str, "~r~~h~%s~w~ (~y~%d~w~)", iTeam[TEAM_B][Name], iTeam[TEAM_B][TeamRounds]);
                TextDrawSetString(TextDraw_RoundStats[3], str);

				if( iTeam[TEAM_B][TeamRole] == ATTACKERS ) {
				    TextDrawSetString(TextDraw_RoundStats[5], "hud:radar_emmetGun");
				}
				else if( iTeam[TEAM_B][TeamRole] == DEFENDERS ) {
				    TextDrawSetString(TextDraw_RoundStats[5], "hud:radar_enemyAttack");
				}

			}
		}
		case TD_PART_CENTER: {
	        if(gConfig[RoundStarted]) {
				if(gConfig[RoundCPTime] != gConfig[ConfigCPTime]) {
				    format(str, sizeof str, "~r~~h~Checkpoint: %d", gConfig[RoundCPTime]);
				}
	            else {
					format(str, sizeof str, "~g~~h~%d:%d", gConfig[RoundTime], gConfig[RoundSecs]);
				}
				TextDrawSetString(TextDraw_RoundStats[1], str);
			}
			else {
				format(str, sizeof str, "| ~y~Lobby~w~ (~b~~h~~h~%d/%d~w~) |", gConfig[CurrentRound], gConfig[TotalRounds]);
                TextDrawSetString(TextDraw_RoundStats[1], str);
			}
		}
	}
	return 1;
}

stock TeamSwaps() {
	if(iTeam[TEAM_A][TeamRole] == ATTACKERS) {
	    iTeam[TEAM_A][TeamRole] = DEFENDERS;
	    iTeam[TEAM_B][TeamRole] = ATTACKERS;
	}
	else if(iTeam[TEAM_A][TeamRole] == DEFENDERS) {
	    iTeam[TEAM_A][TeamRole] = ATTACKERS;
	    iTeam[TEAM_B][TeamRole] = DEFENDERS;
	}
	else {
	    iTeam[TEAM_A][TeamRole] = ATTACKERS;
	    iTeam[TEAM_B][TeamRole] = DEFENDERS;
	}
	SendClientMessageToAll(COLOR_GREEN, "** Team swapped");
}

stock GetRoleName(role) {
	new str[ 24 ];
	str = "-";
	switch(role) {
	    case ATTACKERS: str = "Attackers";
		case DEFENDERS: str = "Defenders";
		case REFEREE:   str = "Referee";
	}
	return str;
}

stock GetDefenders() {
	if(iTeam[TEAM_A][TeamRole] == DEFENDERS) {
	    return TEAM_A;
	}
	return TEAM_B;
}

stock GetAttackers() {
	if(iTeam[TEAM_A][TeamRole] == ATTACKERS) {
	    return TEAM_A;
	}
	return TEAM_B;
}

stock BaseFile(id) {
	new
		str[ 128 ]
	;
	format(str, sizeof str, "%s/bases/%d.ini", SCRIPT_LOCATION, id);
	return str;
}

stock ArenaFile(id) {
	new
		str[ 128 ]
	;
	format(str, sizeof str, "%s/arenes/%d.ini", SCRIPT_LOCATION, id);
	return str;
}

GetVehicleModelIDFromName(vname[])
{
	for(new i = 0; i < 211; i++)
	{
		if ( strfind(aVehicleNames[i], vname, true) != -1 )
			return i + 400;
	}
	return -1;
}

stock CreateVehicleEx(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay, world = 0) {
	new veh = CreateVehicle(modelid, Float:x, Float:y, Float:z, Float:angle, color1, color2, respawn_delay);
	VehLabel[veh] = Create3DTextLabel(aVehicleNames[modelid-400], 0xA61100AA, 0.0, 0.0, 0.0, 40.0, world);
	Attach3DTextLabelToVehicle(VehLabel[veh], veh, 0.0, 0.0, 0.5);
	return veh;
}

forward MarksUpdate();
public MarksUpdate() {
	if(!gConfig[RoundStarted]) return 1;
	foreach(new p:Player) {
		foreach(new i:Player) {
		    if(!iPlayer[i][InGame]) continue;
			if(iPlayer[i][Team] == iPlayer[p][Team]) {
		    	SetPlayerMarkerForPlayer(p, i, GetPlayerColor(i) | 0x000000FF);
			}
			else {
			    SetPlayerMarkerForPlayer(p, i, GetPlayerColor(i) & 0x000000FF);
			}
		}
	}
	return SetTimer("MarksUpdate", 500, 0);
}

stock strExplode(szStr[], const szDelim[], szOutput[][], const iSize = sizeof(szOutput)) {
    new
        i,
        iPos,
        iLen = strlen(szStr)
    ;
    do {
        iPos += strCopyEx(szStr[iPos], szOutput[i], szDelim[0], iLen) + 1;
    }
    while(iPos < iLen && ++i < iSize);
    return i;
}

stock strCopyEx(szSrc[], szDest[], const szDelim[], iSize = sizeof(szDest)) {
    new
        iPos
    ;
    if((iPos = strfind(szSrc, szDelim[0], true)) != -1) {
        szSrc[iPos] = EOS;
        iSize = strcat(szDest, szSrc, iSize);
        szSrc[iPos] = szDelim[0];
    }
    else {
        strcat(szDest, szSrc, iSize);
    }
    return iSize;
}
